﻿package mortal.game.view.signUp
{
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.CollectExchange.panel.*;
    import mortal.game.view.DoubleElevenCollectExchange.*;
    import mortal.game.view.LineOffReward.panel.*;
    import mortal.game.view.common.*;
    import mortal.game.view.levelReward.panel.*;
    import mortal.game.view.rebate.openServerSevenDay.panel.*;
    import mortal.game.view.signUp.data.*;
    import mortal.game.view.signUp.lineOn.panel.*;
    import mortal.game.view.signUp.util.*;
    import mortal.game.view.signUp.view.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class SignUpModule extends BaseWindow
    {
        private var _pageTabData:Array;
        private var _signUpCategorySpr:SignUpCategorySpr;
        private var _clsVec:Vector.<Class>;
        private var _titleArr:Array;
        private var _currSelView:SignUpViewBase;
        private var _isLoadCompl:Boolean;
        public var lineOffExpPanel:LineOffRewardExpPanel;
        public var lineOffCopyPanel:LineOffRewardCopyPanel;
        public var lineOnGiftPanel:LineOnGetRewardPanel;
        private var _isDefault:Boolean;
        private var _currSelTag:int;

        public function SignUpModule(param1:ILayer = null)
        {
            this._clsVec = new Vector.<Class>;
            this._titleArr = Language.getArray(41370);
            this.initTabData();
            super(param1);
            setSize(899, 613 - 30);
            title = Language.getString(41371);
            return;
        }// end function

        private function initTabData() : void
        {
            this._pageTabData = [{label:Language.getString(41372), name:"daliySignUp"}];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.initPanelClass();
            this.addListeners();
            LoaderHelp.addResCallBack(ResFileConst.signUp, this.onResLoadCompl);
            return;
        }// end function

        private function initPanelClass() : void
        {
            this._clsVec.push(DailySignUpView);
            this._clsVec.push(LevelRewardVipUpGiftPanel);
            this._clsVec.push(LineOnGetRewardPanel);
            this._clsVec.push(LineOffRewardCopyPanel);
            this._clsVec.push(LineOffRewardExpPanel);
            this._clsVec.push(ActivationTakeView);
            this._clsVec.push(RedPacketPanel);
            this._clsVec.push(CollectExchangePanel);
            this._clsVec.push(DoubleElevenCollectExchangePanel);
            return;
        }// end function

        private function onResLoadCompl() : void
        {
            this._isLoadCompl = true;
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.bg(8, 66 - 30, 193, 541 + 4 + 2, this));
            this._signUpCategorySpr = UICompomentPool.getUICompoment(SignUpCategorySpr);
            this._signUpCategorySpr.x = 13;
            this._signUpCategorySpr.y = 71 - 30;
            this.addChild(this._signUpCategorySpr);
            this.setDefaultPanel();
            this.updateAllTabShine();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.SignUpSwitchTag, this.onSwitchTagHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.SignUpSwitchTag, this.onSwitchTagHandler);
            return;
        }// end function

        private function setDefaultPanel() : void
        {
            this._signUpCategorySpr.switchTagByIndex(SignUpConst.Tag_DailySignUp);
            this.switchPanel(SignUpConst.Tag_DailySignUp);
            return;
        }// end function

        private function onSwitchTagHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            this.switchPanel(_loc_2);
            return;
        }// end function

        private function switchPanel(param1:int) : void
        {
            this.clearPanel();
            var _loc_2:* = UICompomentPool.getUICompoment(this._clsVec[param1]);
            if (_loc_2 != this._currSelView)
            {
                if (this._currSelView && !this._currSelView.isDisposed)
                {
                    this._currSelView.dispose();
                }
            }
            if (_loc_2 is RedPacketPanel)
            {
                _loc_2.x = 208;
                _loc_2.y = 66 - 30 + 5;
            }
            else
            {
                _loc_2.x = 203;
                _loc_2.y = 66 - 30;
            }
            this.addChild(_loc_2);
            this._currSelView = _loc_2;
            this.setPanel(_loc_2, param1);
            var _loc_3:* = this._titleArr[param1].label;
            _loc_3 = _loc_3 == null ? (this._titleArr[0].label) : (_loc_3);
            this.title = "" + _loc_3;
            return;
        }// end function

        public function openAndSelTag(param1:int) : void
        {
            Cache.instance.signUp.SetTagNameDic();
            var _loc_2:* = Cache.instance.signUp.getTagOpenStateByIndex(param1);
            if (_loc_2 == 1)
            {
                MsgManager.showRollTipsMsg(Language.getString(41373));
                return;
            }
            if (_loc_2 == 2)
            {
                MsgManager.showRollTipsMsg(Language.getString(41374));
                return;
            }
            if (_loc_2 == 3)
            {
                MsgManager.showRollTipsMsg(Language.getString(41375));
                return;
            }
            this._currSelTag = param1;
            if (isHide)
            {
                this.show();
            }
            if (!this._isLoadCompl)
            {
                Global.stage.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            }
            else
            {
                this._signUpCategorySpr.switchTagByIndex(param1);
                this.switchPanel(param1);
            }
            return;
        }// end function

        private function onEnterFrame(event:Event) : void
        {
            if (isDisposed)
            {
                Global.stage.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            }
            if (this._isLoadCompl && !this.isHide)
            {
                Global.stage.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
                this._signUpCategorySpr.switchTagByIndex(this._currSelTag);
                this.switchPanel(this._currSelTag);
            }
            return;
        }// end function

        private function onTabBarChange(event:MuiEvent) : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.signUp, this.onResLoadCompl);
            if (this._signUpCategorySpr)
            {
                this._signUpCategorySpr.dispose(param1);
            }
            if (this._currSelView)
            {
                this._currSelView.dispose(param1);
            }
            this._signUpCategorySpr = null;
            this._currSelView = null;
            this._clsVec.length = 0;
            this.removeListeners();
            this.clearPanel();
            return;
        }// end function

        private function clearPanel() : void
        {
            this.lineOffExpPanel = null;
            this.lineOffCopyPanel = null;
            this.lineOnGiftPanel = null;
            return;
        }// end function

        private function setPanel(param1:SignUpViewBase, param2:int) : void
        {
            var _loc_3:* = this._clsVec[param2];
            _loc_3 = param1 as LineOffRewardExpPanel;
            if (_loc_3)
            {
                this.lineOffExpPanel = _loc_3;
            }
            else
            {
                _loc_3 = param1 as LineOffRewardCopyPanel;
                if (_loc_3)
                {
                    this.lineOffCopyPanel = _loc_3;
                }
                else
                {
                    _loc_3 = param1 as LineOnGetRewardPanel;
                    if (_loc_3)
                    {
                        this.lineOnGiftPanel = _loc_3;
                    }
                }
            }
            return;
        }// end function

        public function get currSelView() : SignUpViewBase
        {
            return this._currSelView;
        }// end function

        public function checkTagIsSatisfy() : void
        {
            if (this._signUpCategorySpr)
            {
                this._signUpCategorySpr.checkTagIsSatisfy();
            }
            return;
        }// end function

        public function checkLineOnBtnShine() : void
        {
            if (this._signUpCategorySpr)
            {
                this._signUpCategorySpr.updateSingleTabShine(SignUpTabType.LineOnGetReward);
            }
            return;
        }// end function

        public function updateAllTabShine() : void
        {
            if (this._signUpCategorySpr)
            {
                this._signUpCategorySpr.updateAllRewardTab();
            }
            return;
        }// end function

    }
}
